package com.zhangbo.study.designpatternlearning.observer;

public class ObserverRun {

    public static void main(String[] args) {
        WeatherData weatherData = new WeatherData();
        CurrentConditionsDisplay currentConditionsDisplay = new CurrentConditionsDisplay(weatherData,"通知面板1");
        CurrentConditionsDisplay currentConditionsDisplay2 = new CurrentConditionsDisplay(weatherData,"通知面板2");
        //数据变更时，自动通知观察者
        weatherData.setMeasurements(80f, 65f, 30.4f);
        weatherData.setMeasurements(60f, 50f, 30.4f);
        //移除通知面板2，加入通知面板3
        System.out.println("移除通知面板2，加入通知面板3");
        weatherData.deleteObserver(currentConditionsDisplay2);
        CurrentConditionsDisplay currentConditionsDisplay3 = new CurrentConditionsDisplay(weatherData,"通知面板3");
        weatherData.setMeasurements(40f, 50f, 30.4f);
        //移除所有通知
        System.out.println("移除所有通知");
        weatherData.deleteObservers();
        weatherData.setMeasurements(20f, 50f, 30.4f);
    }

}
